package com.lsh.payment.worker.service;

import com.lsh.payment.core.constant.BusinessConstant;
import com.lsh.payment.core.model.task.PayTask;
import com.lsh.payment.core.model.notify.PayNotifyTask;
import com.lsh.payment.core.service.paytask.PayTaskService;
import com.lsh.payment.core.service.payment.impl.PaymentNotifyTaskService;
import com.lsh.payment.worker.model.PaymentMonitor;
import com.lsh.payment.worker.task.PaymentNotifyJop;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Project Name: lsh-payment
 *
 * @author peter
 * @date 16/11/13
 * 北京链商电子商务有限公司
 * Package
 * desc:
 */
@Service
public class PaymentMonitorService {

    private static Logger logger = LoggerFactory.getLogger(PaymentNotifyJop.class);

    private static int maxTimes = 10;

    @Autowired
    private PayTaskService payTaskService;

    @Autowired
    private PaymentNotifyTaskService paymentNotifyTaskService;


    /**
     * @return
     */
    public PaymentMonitor monitorPaymentTask() {

        logger.info("monitorPaymentTask maxTimes = {}", maxTimes);
        List<PayTask> payTaskList = payTaskService.selectTasksForMonitor(maxTimes);
        List<PayNotifyTask> payNotifyTaskList = paymentNotifyTaskService.selectTasks(BusinessConstant.TMS_TASK_STATUS_FAIL);

        PaymentMonitor paymentMonitor = new PaymentMonitor();
        paymentMonitor.setPayNotifyTaskList(payNotifyTaskList);
        paymentMonitor.setPayTaskList(payTaskList);

        return paymentMonitor;
    }

//    /**
//     * @return
//     */
//    public boolean deletePaymentNotifyTask() {
//
//        int deleteFlag = paymentNotifyTaskService.deletePayTasks(BusinessConstant.TMS_TASK_STATUS_SUCCESS);
//
//        return deleteFlag > 0;
//    }


}
